CronSchedule Module

History

current version 1.0 - 28th March 2024

version date comment
1.0 28/Mar/2024 Original code
1.1 03/Apr/2024 function CronNextTime

License

license: GNU GPL http://www.gnu.org/licenses/

This file is part of

MOSAICO -- MOdular library for raSter bAsed hydrologIcal appliCatiOn.

Copyright (C) 2011 Giovanni Ravazzani

Code Description

Language: Fortran 90.

Software Standards: "European Standards for Writing and
Documenting Exchangeable Fortran 90 Code".

Module Description:

Set of fortran routines to manage process scheduling. The module mimics the way CRONTAB is used on Linux operating system to schedule processes. Firstly a string is parsed to set when a process is started. The function CronParseString is called to parse the string. The string is an expression made of five fields which represent the time to start a process:

 |------------- minute (0-59)
 | |------------- hour (0-23)
 | | |------------ day of the month (1-31)
 | | | |------------ month (1-12)
 | | | | |------------ day of the week (0-6) (Sunday to Saturday)
 | | | | |
 | | | | |
 | | | | |
 * * * * * 

Some examples:

0 * * * * once an hour at the beginning of the hour

0 0 * * * once a day at midnight

0 0 * * 0 once a week at midnight on Sunday

0 0 1 * * once a month at midnight of the first day of the month

0 0 1 1 * once a year at midnight of 1 January

The function CronIsTime check when the time to execute a process is reached.

References:

https://en.wikipedia.org/wiki/Cron



Derived Types

type, public ::  CronTab

Components

Type Visibility Attributes Name Initial
integer(kind=short), public :: daysOfMonth(31)
integer(kind=short), public :: daysOfWeek(0:6)
integer(kind=short), public :: hours(0:23)
integer(kind=short), public :: minutes(0:59)
integer(kind=short), public :: months(12)
character(len=300), public :: string

Functions

public function CronIsTime(time, cron) result(yes)

returns true if it is time to start a process

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time
type(CronTab), intent(in) :: cron

Return Value logical

public function CronNextTime(time, cron) result(next)

returns the next time to start a process given the current time

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time

current time

type(CronTab), intent(in) :: cron

cron table

Return Value type(DateTime)


Subroutines

public subroutine CronParseString(cronString, cron)

parse cron string

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: cronString
type(CronTab), intent(out) :: cron